package com.kaithan.framework.common.threadpool;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 类描述：线程池助手
 *
 * @author ZhuYin
 * @since 2024年12月26日
 */
@Component
@ConditionalOnBean(value = ThreadPoolConfig.class)
public class ThreadPoolHelper {

    public static ThreadPoolExecutor cpuIntensiveThreadPool;
    @Resource(name = "cpuIntensiveThreadPool")
    public void setAsyncExecutor1(ThreadPoolExecutor cpuIntensiveThreadPool) {
        ThreadPoolHelper.cpuIntensiveThreadPool = cpuIntensiveThreadPool;
    }

    public static ThreadPoolExecutor ioIntensiveThreadPool;
    @Resource(name = "ioIntensiveThreadPool")
    public void setAsyncExecutor2(ThreadPoolExecutor ioIntensiveThreadPool) {
        ThreadPoolHelper.ioIntensiveThreadPool = ioIntensiveThreadPool;
    }

    public static ThreadPoolExecutor scheduledThreadPool;
    @Resource(name = "scheduledThreadPool")
    public void setAsyncExecutor3(ThreadPoolExecutor scheduledThreadPool) {
        ThreadPoolHelper.scheduledThreadPool = scheduledThreadPool;
    }

    public static ThreadPoolExecutor asyncTaskThreadPool;
    @Resource(name = "asyncTaskThreadPool")
    public void setAsyncExecutor4(ThreadPoolExecutor asyncTaskThreadPool) {
        ThreadPoolHelper.asyncTaskThreadPool = asyncTaskThreadPool;
    }

    public static ThreadPoolExecutor asyncLogTaskThreadPool;
    @Resource(name = "asyncLogTaskThreadPool")
    public void setAsyncExecutor5(ThreadPoolExecutor asyncLogTaskThreadPool) {
        ThreadPoolHelper.asyncLogTaskThreadPool = asyncLogTaskThreadPool;
    }

}
